package com.linck.im.client.context;

import com.linck.im.model.proto.ProtoMsg;

import java.util.*;

/**
 * @author: linck
 * @create: 2021-08-23
 */
public class ChatContext {
    private static Map<String, List<ProtoMsg.Message>> messageMap = new HashMap<>();

    public static void init(List<String> accounts) {
        for (String account : accounts) {
            if (!messageMap.containsKey(account)) {
                messageMap.put(account, new ArrayList<>());
            }
        }
    }

    public static void receiveMessage(ProtoMsg.Message message) {
        if (!messageMap.containsKey(message.getFrom())) {
            messageMap.put(message.getFrom(), new ArrayList<>());
        }
        List<ProtoMsg.Message> messageList = messageMap.get(message.getFrom());
        messageList.add(message);
    }

    public static void sendMessage(ProtoMsg.Message message) {
        if (!messageMap.containsKey(message.getTo())) {
            messageMap.put(message.getTo(), new ArrayList<>());
        }
        List<ProtoMsg.Message> messageList = messageMap.get(message.getTo());
        messageList.add(message);
    }

    public static List<ProtoMsg.Message> getMessages(String account) {
        return messageMap.get(account);
    }
}
